package br.com.projeto.persistence;

import org.hibernate.Query;
import org.hibernate.Session;
import org.hibernate.Transaction;

import br.com.projeto.hibernate.HibernateUtil;

public class GenericDAO<O> {

    Session session;
    Transaction transaction;
    Query query;

    public void create(O o) throws Exception{
        session = HibernateUtil.getSessionFactory().openSession();
        transaction = session.beginTransaction();
        session.save(o);
        transaction.commit();
    }

    public void update(O o) throws Exception{
        session = HibernateUtil.getSessionFactory().openSession();
        transaction = session.beginTransaction();
        session.update(o);
        transaction.commit();
    }

    public void delete(O o) throws Exception{
        session = HibernateUtil.getSessionFactory().openSession();
        transaction = session.beginTransaction();
        session.delete(o);
        transaction.commit();
    }

}
